package com.example.live.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.live.databinding.UserItemBinding
import com.example.live.entity.UserEntity

import javax.inject.Inject

class RankingAll2Adapter @Inject constructor(private val data:List<UserEntity>):RecyclerView.Adapter<RankingAll2Adapter.commentsViewHolder>() {
    inner class commentsViewHolder(val itembinding: UserItemBinding):RecyclerView.ViewHolder(itembinding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): commentsViewHolder {
        return commentsViewHolder(UserItemBinding.inflate(LayoutInflater.from(parent.context),parent,false))
    }
    private var itemOnClickListener:ItemOnClickListener ?=null
    fun setOnClickLister(listener: ItemOnClickListener){
        this.itemOnClickListener = listener
    }

    override fun getItemCount(): Int = data.size

    override fun onBindViewHolder(holder: commentsViewHolder, position: Int) {
        val entity = data[position]
        holder.itembinding.apply {
            tvtv.setText("${position+1}")
            tv001.setText(entity.username)
            tvGz.setOnClickListener {
                itemOnClickListener?.OnClick(it,position)
            }
        }
    }
    interface ItemOnClickListener{
        fun OnClick(view:View,position: Int){

        }
    }

}